package com.pb.infra.auth.controller;

import com.pb.infra.auth.service.PriviResAuthService;
import com.pb.infra.oth.entity.common.Page;
import com.pb.infra.oth.entity.common.Result;
import com.pb.infra.oth.util.Constant;
import com.pb.infra.oth.util.SysLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 资源管理
 * @author liudebao
 * @date 2022/11/30
 */
@Slf4j
@RestController
@RequestMapping("v1/system/resAuth")
public class PriviResAuthController {

    /**
     * 日志操作表
     */
    private static final String TABLE_NAME = "PRIVI_RESOURCE";

    /**
     * 日志操作功能名
     */
    private static final String OPERATION_MENU = "资源管理";

    /**
     * 业务逻辑对象
     */
    @Resource
    private PriviResAuthService priviResAuthService;

    /**
     * 读取资源信息
     * @param paramMap 请求参数
     * @return Result 返回数据
     */
    @GetMapping("getResData")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.QUERY, menuName = OPERATION_MENU)
    public Result getResData(@RequestParam Map<String, Object> paramMap, Page page) {
        return priviResAuthService.getResData(paramMap, page);
    }

    /**
     * 新建资源信息
     * @param paramMap 请求参数
     * @return Result 返回数据
     */
    @PostMapping("insert")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.ADD, menuName = OPERATION_MENU)
    public Result insert(@RequestBody Map<String, Object> paramMap, HttpServletRequest request) {
        return priviResAuthService.insert(paramMap, request);
    }

    /**
     * 修改资源信息
     * @param paramMap 请求参数
     * @param request
     * @return
     */
    @PostMapping("update")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.MOD, menuName = OPERATION_MENU)
    public Result update(@RequestBody Map<String, Object> paramMap, HttpServletRequest request) {
        priviResAuthService.update(paramMap, request);
        return Result.OK_EMPTY;
    }

    /**
     * 修改资源信息
     * @param paramMap 请求参数
     * @return
     */
    @PostMapping("delRes")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.DEL, menuName = OPERATION_MENU)
    public Result delRes(@RequestBody List<String> paramMap) {
        priviResAuthService.delRes(paramMap);
        return Result.OK_EMPTY;
    }

}
